package com.softserveinc.dao.mapper;

import com.softserveinc.model.Role;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.security.core.GrantedAuthority;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Extracts data from database and casts it to Role
 */
public class RoleResultSetExtractor implements ResultSetExtractor<GrantedAuthority> {
    /**
     *
     * @param resultSet - for extracting data
     * @return Role object
     * @throws SQLException
     * @throws DataAccessException
     */
    @Override
    public Role extractData(ResultSet resultSet) throws SQLException, DataAccessException {
        Role role = new Role();
        role.setId(resultSet.getInt(1));
        role.setAuthority(resultSet.getString(2));
        return role;
    }
}
